// MyFamily - XML based genealogy program.
// Copyright (C) 2006  Doug Swisher
// See the file COPYING.txt for license details.

using System;
using System.Collections.Generic;
using System.Text;

using NUnit.Framework;


namespace DataModel
{
    public class FamilyDate
    {
        private int year;
        private int month;
        private int day;


        public static FamilyDate Parse(string text)
        {
            FamilyDate temp = new FamilyDate();

            DateTime foo = DateTime.Parse(text);

            temp.year = foo.Year;
            temp.month = foo.Month;
            temp.day = foo.Day;

            return temp;
        }


        public int Year
        {
            get { return this.year; }
        }


        public int Month
        {
            get { return this.month; }
        }


        public int Day
        {
            get { return this.day; }
        }
    }



    [TestFixture]
    public class FamilyDateTests
    {

        [Test]
        public void SimpleParse()
        {
            FamilyDate date = FamilyDate.Parse("12 JUN 2006");

            Assert.IsNotNull(date);
            Assert.AreEqual(2006, date.Year, "Year mismatch");
            Assert.AreEqual(6, date.Month, "Month mismatch");
            Assert.AreEqual(12, date.Day, "Day mismatch");
        }



        private void CheckMonth(string text, int expectedMonth)
        {
            FamilyDate date = FamilyDate.Parse(text);

            Assert.AreEqual(expectedMonth, date.Month, string.Format("Month mismatch: {0}", text));
        }


        [Test]
        public void TestAllMonths()
        {
            CheckMonth("JAN 2001", 1);
            CheckMonth("FEB 2001", 2);
            CheckMonth("MAR 2001", 3);
            CheckMonth("APR 2001", 4);
            CheckMonth("MAY 2001", 5);
            CheckMonth("JUN 2001", 6);
            CheckMonth("JUL 2001", 7);
            CheckMonth("AUG 2001", 8);
            CheckMonth("SEP 2001", 9);
            CheckMonth("OCT 2001", 10);
            CheckMonth("NOV 2001", 11);
            CheckMonth("DEC 2001", 12);
        }

    }
}
